import 'Person.dart';

int counter = 1;

class MovieItem {
  int? rank;
  String? imageURL;
  String? title;
  String? playDate;
  double? rating;
  List<String>? genres;
  List<Actor>? casts;
  Director? director;
  String? originalTitle;

  MovieItem(this.rank, this.imageURL, this.title, this.playDate, this.rating, this.genres,
      this.casts, this.director, this.originalTitle);

  MovieItem.fromMap(Map<String, dynamic> json) {
    rank = counter++;
    imageURL = json["images"]["medium"];
    title = json["title"];
    playDate = json["year"];
    rating = json["rating"]["average"];
    genres = json["genres"].cast<String>();
    casts = (json["casts"] as List<dynamic>).map((item) {
      return Actor.fromMap(item);
    }).toList();
    director = Director.fromMap(json["directors"][0]);
    originalTitle = json["original_title"];
  }

  @override
  String toString() {
    return 'MovieItem{rank: $rank, imageURL: $imageURL, title: $title, playDate: $playDate, rating: $rating, genres: $genres, casts: $casts, director: $director, originalTitle: $originalTitle}';
  }
}
